# 会覆盖原文件
with open("./17_write_file.txt", "w", encoding="utf-8") as f:
    f.writelines("床前明月光\n")
    f.writelines("疑是地上霜\n")
    f.writelines("举头望五月\n")
    f.writelines("低头思故乡")

print("文件写入完毕")

# 追加书写
with open("./17_write_file.txt", "a", encoding="utf-8") as f:
    f.write("\n")
    f.write("这是追加的内容，哈哈哈哈")


# r+ 代表：先读，再写。
with open("./17_write_file.txt", "r+", encoding="utf-8") as f:
    # 读一行
    print(f.readline())
    f.write("\n吃惊吗，哈哈哈哈哈哈a")